<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://schemas.microsoft.com/developer/msbuild/2003" xmlns:msb="http://schemas.microsoft.com/developer/msbuild/2003" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <!-- ======================================================================================= -->
    <xs:element name="Project">
         <xs:annotation>
            <xs:documentation><!-- _locID_text="Project" _locComment="" -->An MSBuild Project</xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:sequence>
                <xs:group ref="msb:ProjectLevelTagExceptTargetOrImportType" minOccurs="0" maxOccurs="unbounded"/>
                <!-- must be at least one Target or Import tag-->
                <xs:group ref="msb:TargetOrImportType"/>
                <xs:group ref="msb:ProjectLevelTagType" minOccurs="0" maxOccurs="unbounded"/>
            </xs:sequence>
            <xs:attribute name="DefaultTargets" type="xs:string" use="optional">
                <xs:annotation>
                    <xs:documentation><!-- _locID_text="Project_DefaultTargets" _locComment="" -->Optional semi-colon separated list of one or more targets that will be built if no targets are otherwise specified</xs:documentation>
                </xs:annotation>
            </xs:attribute>
            <xs:attribute name="InitialTargets" type="xs:string" use="optional">
                <xs:annotation>
                    <xs:documentation><!-- _locID_text="Project_InitialTargets" _locComment="" -->Optional semi-colon separated list of targets that should always be built before any other targets</xs:documentation>
                </xs:annotation>
            </xs:attribute>
        </xs:complexType>
    </xs:element>
    <!-- ======================================================================================= -->
    <xs:group name="ProjectLevelTagExceptTargetOrImportType">
        <xs:choice>
            <xs:element name="PropertyGroup" type="msb:PropertyGroupType"/>
            <xs:element name="ItemGroup" type="msb:ItemGroupType"/>
            <xs:element name="Choose" type="msb:ChooseType"/>
            <xs:element name="UsingTask" type="msb:UsingTaskType"/>
            <xs:element name="ProjectExtensions" type="msb:ProjectExtensionsType"/>
        </xs:choice>
    </xs:group>
    <!-- ======================================================================================= -->    
    <xs:group name="ProjectLevelTagType">
        <xs:choice>
            <xs:element name="PropertyGroup" type="msb:PropertyGroupType"/>
            <xs:element name="ItemGroup" type="msb:ItemGroupType"/>
            <xs:element name="Choose" type="msb:ChooseType"/>
            <xs:element name="UsingTask" type="msb:UsingTaskType"/>
            <xs:element name="Target" type="msb:TargetType"/>
            <xs:element name="Import" type="msb:ImportType"/>
            <xs:element name="ProjectExtensions" type="msb:ProjectExtensionsType"/>
        </xs:choice>
    </xs:group>
    <!-- ======================================================================================= -->
    <xs:group name="TargetOrImportType">
        <xs:choice>
            <xs:element name="Target" type="msb:TargetType"/>
            <xs:element name="Import" type="msb:ImportType"/>
        </xs:choice>
    </xs:group>    
    <!-- ======================================================================================= -->        
    <xs:complexType name="TargetType">
        <xs:annotation>
            <xs:documentation><!-- _locID_text="TargetType" _locComment="" -->Groups tasks into a section of the build process</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:choice minOccurs="0" maxOccurs="unbounded">
                <xs:element ref="msb:Task"/>
            </xs:choice>
            <xs:element name="OnError" type="msb:OnErrorType" minOccurs="0" maxOccurs="unbounded"/>
            <!-- no elements are allowed under Target after an OnError element-->
        </xs:sequence>
        <xs:attribute name="Name" type="msb:non_empty_string" use="required">
            <xs:annotation>
                <xs:documentation><!-- _locID_text="TargetType_Name" _locComment="" -->Name of the target</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="DependsOnTargets" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation><!-- _locID_text="TargetType_DependsOnTargets" _locComment="" -->Optional semi-colon separated list of targets that should be run before this target</xs:documentation>
            </xs:annotation>
        </xs:attribute>            
        <xs:attribute name="Inputs" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation><!-- _locID_text="TargetType_Inputs" _locComment="" -->Optional semi-colon separated list of files that form inputs into this target. Their timestamps will be compared with the timestamps of files in Outputs to determine whether the Target is up to date</xs:documentation>
            </xs:annotation>
        </xs:attribute>                
        <xs:attribute name="Outputs" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation><!-- _locID_text="TargetType_Outputs" _locComment="" -->Optional semi-colon separated list of files that form outputs into this target. Their timestamps will be compared with the timestamps of files in Inputs to determine whether the Target is up to date</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="Condition" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation><!-- _locID_text="TargetType_Condition" _locComment="" -->Optional expression evaluated to determine whether the Target and the targets it depends on should be run</xs:documentation>
            </xs:annotation>
        </xs:attribute>            
    </xs:complexType>
    <!-- ======================================================================================= -->        
    <xs:complexType name="PropertyGroupType">
        <xs:annotation>
            <xs:documentation><!-- _locID_text="PropertyGroupType" _locComment="" -->Groups property definitions</xs:documentation>
        </xs:annotation>
        <xs:sequence minOccurs="0" maxOccurs="unbounded">
            <xs:element ref="msb:Property"/>
        </xs:sequence>
        <xs:attribute name="Condition" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation><!-- _locID_text="PropertyGroupType_Condition" _locComment="" -->Optional expression evaluated to determine whether the PropertyGroup should be used</xs:documentation>
            </xs:annotation>
        </xs:attribute>                
    </xs:complexType>
    <!-- ======================================================================================= -->        
    <xs:complexType name="ItemGroupType">
        <xs:annotation>
            <xs:documentation><!-- _locID_text="ItemGroupType" _locComment="" -->Groups item list definitions</xs:documentation>
        </xs:annotation>        
        <xs:sequence minOccurs="0" maxOccurs="unbounded">
            <xs:element ref="msb:Item"/>
        </xs:sequence>
        <xs:attribute name="Condition" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation><!-- _locID_text="ItemGroupType_Condition" _locComment="" -->Optional expression evaluated to determine whether the ItemGroup should be used</xs:documentation>
            </xs:annotation>
        </xs:attribute>                
    </xs:complexType>
    <!-- ======================================================================================= -->
    <xs:complexType name="ChooseType">
        <xs:annotation>
            <xs:documentation><!-- _locID_text="ChooseType" _locComment="" -->Groups When and Otherwise elements</xs:documentation>
        </xs:annotation>
        <xs:sequence>
            <xs:element name="When" type="msb:WhenType" maxOccurs="unbounded"/>
            <xs:element name="Otherwise" type="msb:OtherwiseType" minOccurs="0"/>
        </xs:sequence>
    </xs:complexType>
    <!-- ======================================================================================= -->
    <xs:complexType name="WhenType">
        <xs:annotation>
            <xs:documentation><!-- _locID_text="WhenType" _locComment="" -->Groups PropertyGroup and/or ItemGroup elements</xs:documentation>
        </xs:annotation>
        <xs:sequence minOccurs="0" maxOccurs="unbounded">
            <xs:choice>
                <xs:element name="PropertyGroup" type="msb:PropertyGroupType"/>
                <xs:element name="ItemGroup" type="msb:ItemGroupType"/>
                <xs:element name="Choose" type="msb:ChooseType"/>
            </xs:choice>
        </xs:sequence>
        <xs:attribute name="Condition" type="xs:string" use="required">
            <xs:annotation>
                <xs:documentation><!-- _locID_text="WhenType_Condition" _locComment="" -->Optional expression evaluated to determine whether the child PropertyGroups and/or ItemGroups should be used</xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>
    <!-- ======================================================================================= -->
    <xs:complexType name="OtherwiseType">
        <xs:annotation>
            <xs:documentation><!-- _locID_text="OtherwiseType" _locComment="" -->Groups PropertyGroup and/or ItemGroup elements that are used if no Conditions on sibling When elements evaluate to true</xs:documentation>
        </xs:annotation>        
        <xs:sequence minOccurs="0" maxOccurs="unbounded">
            <xs:choice>
                <xs:element name="PropertyGroup" type="msb:PropertyGroupType"/>
                <xs:element name="ItemGroup" type="msb:ItemGroupType"/>
                <xs:element name="Choose" type="msb:ChooseType"/>
            </xs:choice>
        </xs:sequence>
    </xs:complexType>
    <!-- ======================================================================================= -->        
    <xs:complexType name="OnErrorType">
        <xs:annotation>
            <xs:documentation><!-- _locID_text="OnErrorType" _locComment="" -->Specifies targets to execute in the event of a recoverable error</xs:documentation>
        </xs:annotation>
        <xs:attribute name="Condition" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation><!-- _locID_text="OnErrorType_Condition" _locComment="" -->Optional expression evaluated to determine whether the targets should be executed</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="ExecuteTargets" type="msb:non_empty_string" use="required">
            <xs:annotation>
                <xs:documentation><!-- _locID_text="OnErrorType_ExecuteTargets" _locComment="" -->Semi-colon separated list of targets to execute</xs:documentation>
            </xs:annotation>
        </xs:attribute>            
    </xs:complexType>
    <!-- ======================================================================================= -->    
    <xs:complexType name="UsingTaskType">
        <xs:annotation>
            <xs:documentation><!-- _locID_text="UsingTaskType" _locComment="" -->Declares where to load a task that will be used in the project</xs:documentation>
        </xs:annotation>        
        <xs:attribute name="Condition" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation><!-- _locID_text="UsingTaskType_Condition" _locComment="" -->Optional expression evaluated to determine whether the declaration should be evaluated</xs:documentation>
            </xs:annotation>
        </xs:attribute>                
        <xs:attribute name="AssemblyName" type="msb:non_empty_string" use="optional">
            <xs:annotation>
                <xs:documentation><!-- _locID_text="UsingTaskType_AssemblyName" _locComment="" -->Optional name of assembly containing the task. Either AssemblyName or AssemblyFile must be used</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="AssemblyFile" type="msb:non_empty_string" use="optional">
            <xs:annotation>
                <xs:documentation><!-- _locID_text="UsingTaskType_AssemblyFile" _locComment="" -->Optional path to assembly containing the task. Either AssemblyName or AssemblyFile must be used</xs:documentation>
            </xs:annotation>
        </xs:attribute>            
        <xs:attribute name="TaskName" type="msb:non_empty_string" use="required">
            <xs:annotation>
                <xs:documentation><!-- _locID_text="UsingTaskType_TaskName" _locComment="" -->Name of task class in the assembly</xs:documentation>
            </xs:annotation>
        </xs:attribute>             
    </xs:complexType>
    <!-- ======================================================================================= -->  
    <xs:complexType name="ImportType">
        <xs:annotation>
            <xs:documentation><!-- _locID_text="ImportType" _locComment="" -->Declares that the contents of another project file should be inserted at this location</xs:documentation>
        </xs:annotation>        
        <xs:attribute name="Condition" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation><!-- _locID_text="ImportType_Condition" _locComment="" -->Optional expression evaluated to determine whether the import should occur</xs:documentation>
            </xs:annotation>
        </xs:attribute>              
        <xs:attribute name="Project" type="msb:non_empty_string" use="required">
            <xs:annotation>
                <xs:documentation><!-- _locID_text="ImportType_Project" _locComment="" -->Project file to import</xs:documentation>
            </xs:annotation>
        </xs:attribute>            
    </xs:complexType>
    <!-- ======================================================================================= -->  
    <xs:complexType name="ProjectExtensionsType" mixed="true">
        <xs:annotation>
            <xs:documentation><!-- _locID_text="ProjectExtensionsType" _locComment="" -->Optional section used by MSBuild hosts, that may contain arbitrary XML content that is ignored by MSBuild itself</xs:documentation>
        </xs:annotation>
        <xs:sequence minOccurs="0" maxOccurs="unbounded">
            <xs:any processContents="skip"/>
        </xs:sequence>
    </xs:complexType>    
    <!-- ======================================================================================= -->
    <xs:element name="Item" type="msb:SimpleItemType" abstract="true"/>
    <!-- ======================================================================================= -->   
    <!-- convenience type for items that have no meta-data-->
    <xs:complexType name="SimpleItemType">
        <xs:attribute name="Condition" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation><!-- _locID_text="SimpleItemType_Condition" _locComment="" -->Optional expression evaluated to determine whether the items should be evaluated</xs:documentation>
            </xs:annotation>
        </xs:attribute>             
        <xs:attribute name="Include" type="xs:string" use="required">
            <xs:annotation>
                <xs:documentation><!-- _locID_text="SimpleItemType_Include" _locComment="" -->Semi-colon separated list of files (wildcards are allowed) or other item names to include in this item list</xs:documentation>
            </xs:annotation>
        </xs:attribute>             
        <xs:attribute name="Exclude" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation><!-- _locID_text="SimpleItemType_Exclude" _locComment="" -->Semi-colon separated list of files (wildcards are allowed) or other item names to exclude from the Include list</xs:documentation>
            </xs:annotation>
        </xs:attribute>             
    </xs:complexType>
    <!-- ======================================================================================= -->      
    <!-- general utility type allowing an item type to be defined but not its child meta-data-->
    <xs:complexType name="GenericItemType">
        <xs:complexContent>
            <xs:extension base="msb:SimpleItemType">
                <xs:sequence minOccurs="0" maxOccurs="unbounded">
                    <xs:any namespace="##any" processContents="skip"/>  
                </xs:sequence>      
            </xs:extension>
        </xs:complexContent>
    </xs:complexType>
    <!-- ======================================================================================= -->  
    <!-- no type declared on this abstract element, so either a simple or complex type can be substituted for it.-->
    <xs:element name="Property" abstract="true"/>
    <!-- ======================================================================================= -->      
    <!-- convenience type for properties that just want to allow text and no elements in them-->
    <xs:complexType name="StringPropertyType">
        <xs:simpleContent>
            <xs:extension base="xs:string">
                <xs:attribute name="Condition" type="xs:string" use="optional">
                    <xs:annotation>
                        <xs:documentation><!-- _locID_text="StringPropertyType_Condition" _locComment="" -->Optional expression evaluated to determine whether the property should be evaluated</xs:documentation>
                    </xs:annotation>
                </xs:attribute>
            </xs:extension>
        </xs:simpleContent>
    </xs:complexType>
    <!-- ======================================================================================= -->      
    <!-- general utility type allowing text and/or elements inside-->
    <xs:complexType name="GenericPropertyType" mixed="true">
        <xs:sequence minOccurs="0" maxOccurs="unbounded">
            <xs:any namespace="##any" processContents="skip"/>
        </xs:sequence>
        <xs:attribute name="Condition" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation><!-- _locID_text="GenericPropertyType_Condition" _locComment="" -->Optional expression evaluated to determine whether the property should be evaluated</xs:documentation>
            </xs:annotation>
        </xs:attribute>
    </xs:complexType>
    <!-- ======================================================================================= -->
    <xs:element name="Task" type="msb:TaskType" abstract="true"/>
    <!-- ======================================================================================= -->
    <xs:complexType name="TaskType">
        <xs:sequence minOccurs="0" maxOccurs="unbounded">
            <xs:element name="Output">
                <xs:annotation>
                    <xs:documentation><!-- _locID_text="TaskType_Output" _locComment="" -->Optional element specifying a specific task output to be gathered</xs:documentation>
                </xs:annotation>
                <xs:complexType>
                    <xs:attribute name="TaskParameter" type="msb:non_empty_string" use="required">
                        <xs:annotation>
                            <xs:documentation><!-- _locID_text="TaskType_Output_TaskParameter" _locComment="" -->Task parameter to gather. Matches the name of a .NET Property on the task class that has an [Output] attribute</xs:documentation>
                        </xs:annotation>
                    </xs:attribute>
                    <xs:attribute name="ItemName" type="msb:non_empty_string" use="optional">
                        <xs:annotation>
                            <xs:documentation><!-- _locID_text="TaskType_Output_ItemName" _locComment="" -->Optional name of an item list to put the gathered outputs into. Either ItemName or PropertyName must be specified</xs:documentation>
                        </xs:annotation>
                    </xs:attribute>
                    <xs:attribute name="PropertyName" type="msb:non_empty_string" use="optional">
                        <xs:annotation>
                            <xs:documentation><!-- _locID_text="TaskType_Output_PropertyName" _locComment="" -->Optional name of a property to put the gathered output into. Either PropertyName or ItemName must be specified</xs:documentation>
                        </xs:annotation>
                    </xs:attribute>
                    <xs:attribute name="Condition" type="xs:string" use="optional">
                        <xs:annotation>
                            <xs:documentation><!-- _locID_text="TaskType_Output_Condition" _locComment="" -->Optional expression evaluated to determine whether the output should be gathered</xs:documentation>
                        </xs:annotation>
                    </xs:attribute>
                </xs:complexType>
            </xs:element>
        </xs:sequence>
        <xs:attribute name="Condition" type="xs:string" use="optional">
            <xs:annotation>
                <xs:documentation><!-- _locID_text="TaskType_Condition" _locComment="" -->Optional expression evaluated to determine whether the task should be executed</xs:documentation>
            </xs:annotation>
        </xs:attribute>
        <xs:attribute name="ContinueOnError" type="msb:boolean" use="optional">
            <xs:annotation>
                <xs:documentation><!-- _locID_text="TaskType_ContinueOnError" _locComment="" -->Optional boolean indicating whether a recoverable task error should be ignored. Default false</xs:documentation>
            </xs:annotation>
        </xs:attribute>            
        <!-- We don't need the anyAttribute here because other types deriving from this type will add the right attributes.-->
    </xs:complexType>
    <!-- ======================================================================================= -->  
    <!-- XSD considers an empty-valued attribute to satisfy use="required", but we want it to have a non-empty value in most cases, hence this utility type. -->
    <xs:simpleType name="non_empty_string">
        <xs:restriction base="xs:string">
            <xs:minLength value="1"/>
        </xs:restriction>
    </xs:simpleType>
    <!-- This type causes intellisense to suggest "true" or "false", but doesn't actually constrain the value beyond msb:non_empty_string.
    We can't constrain the value, because the project author might want to pass a property or item instead of a literal value.
    Besides, MSBuild will accept other literal values, like "on" and "off", just as well. -->
    <xs:simpleType name="boolean">
        <xs:union memberTypes="msb:non_empty_string">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:enumeration value="true" />
                    <xs:enumeration value="false" />
                </xs:restriction>
            </xs:simpleType>
        </xs:union>
    </xs:simpleType>
    <!-- Similar trick for Importance -->
    <xs:simpleType name="importance">
        <xs:union memberTypes="msb:non_empty_string">
            <xs:simpleType>
                <xs:restriction base="xs:string">
                    <xs:enumeration value="high" />
                    <xs:enumeration value="normal" />
                    <xs:enumeration value="low" />
                </xs:restriction>
            </xs:simpleType>
        </xs:union>
    </xs:simpleType>    
</xs:schema>
